define(function(require){
	var $ = require("jquery");
	//var justep = require("$UI/system/lib/justep");
	var ideService = require("$UI/system/designer/webIde/common/IDEService");
	var xCloudService = ideService.getXCloudService();
	
	var Model = function(){
		this.callParent();
	};

	Model.prototype.modelParamsReceive = function(event){
		var json = event.params.data;
		var id = event.params.fid;
		var rows = [];
		$.each(json,function(i,v){
			if(v.fid==id){
				rows.push(v);
			}
		});
		this.comp("demoData").loadData(rows);
		this.comp("demoData").refreshData();
	};

	Model.prototype.okBtnClick = function(event){
		var  path = "main/yemiansj";
		var tababeName = path.substring(path.lastIndexOf("/")+1,path.length);
		var main = path.substring(0,path.lastIndexOf("/"));
		var filePath ="service/"+main+"/init/"+tababeName+".json";
		var row = this.comp("demoData").getCurrentRow();
		var json =  this.params.data;
		var rows = [];
		$.each(json,function(i,v){
			if(row.val("fid")==v.fid){
				var changeRow = row.toJson({"format":"simple"});
				delete changeRow.userdata;
				rows.push(changeRow);
			}else{
				rows.push(v);
			}
		});
		xCloudService.saveFile({filePath:filePath,content:JSON.stringify(rows)});
		this.owner.send({});
		this.close();
	};

	return Model;
});